﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DocumentSection
    {
        private string _Description;
        private string _ProjectCode;
        private string _Section;

        public DocumentSection(string projectCode, string section, string description)
        {
            this._ProjectCode = projectCode;
            this._Description = description;
        }

        public int GetDocSection()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ProjectName", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, this._ProjectCode.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@SectionDesc", SqlDbType.NVarChar, 0xff, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetDocSectionSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            this._Description = (string) sqlCmd.Parameters["@SectionDesc"].Value;
            return resultValue;
        }

        public string GetDocSectionDesc(string section)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Section", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, section.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@SectionDesc", SqlDbType.NVarChar, 0xff, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetDocSectionDescSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            return (string) sqlCmd.Parameters["@SectionDesc"].Value;
        }

        public int GetDocumentSectionInfo(string section)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Section", SqlDbType.NVarChar, 30, ParameterDirection.Input, section);
            DAL.AddParamToSQLCmd(sqlCmd, "@Description", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "RetrieveDocumentSectionSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            this._Description = (string) sqlCmd.Parameters["@Description"].Value;
            return resultValue;
        }

        public string description
        {
            get
            {
                return this._Description;
            }
            set
            {
                this._Description = value;
            }
        }

        public string projectCode
        {
            get
            {
                return this._ProjectCode;
            }
            set
            {
                this._ProjectCode = value;
            }
        }

        public string section
        {
            get
            {
                return this._Section;
            }
            set
            {
                this._Section = value;
            }
        }
    }
}

